import {
	store
} from "../store/index.js"
const innerAudioContext = uni.createInnerAudioContext();
let audio = null
innerAudioContext.autoplay = true;









export const jxcxzdf = async (text) => {
	if (store.state.isjysd) { //禁音
		return
	}

	store.state.isboxrtt = 1
	if (store.state.ttsText) {
		store.state.isboxrtt = 2
		innerAudioContext.src = store.state.ttsText
		innerAudioContext.play()
		return
	}
	uni.request({
		url: 'https://dxchat.duxinggj.com/dxtts',
		method: "post",
		responseType: "arraybuffer",
		data: {
			text,
			speed: "0.9"
		},
		success: ({
			data
		}) => {
			try {
				innerAudioContext.stop()
			} catch (e) {

			}
		// 调用stop方法可全部关闭录音
		
	
			console.log(data)
			let response = data
			const arrayBuffer = response;
			const blob = new Blob([arrayBuffer], {
				type: "audio/mp3",
			});
			const url = URL.createObjectURL(blob);
			console.log("audio/mp3")
			innerAudioContext.src = url
			innerAudioContext.play()
			store.state.ttsText = url
			store.state.isboxrtt = 2
		},
		fail: (data) => {
			store.state.isboxrtt = 0
			// console.log(55584)
			// 	console.log(data)
		}
	});
}
innerAudioContext.onEnded(() => {
	store.state.isboxrtt = 0
	innerAudioContext.stop()
})

// export const zhsdr = () => {
// 	store.state.isboxrtt = 0
// 	innerAudioContext.stop()
// }
export const zhsdr = () => {
	store.state.isboxrtt = 0
	innerAudioContext.stop()
}


